package com.cqie.tes.comm;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

//统一返回结果的类
// 要删除
@Data
public class TR {

    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;


    @ApiModelProperty(value = "返回数据")
    private Object data;

    //把构造方法私有
    private TR() {}

    //成功静态方法
    public static TR ok() {
        TR r = new TR();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    //失败静态方法
    public static TR error() {
        TR r = new TR();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage("失败");
        return r;
    }

    public TR success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public TR message(String message){
        this.setMessage(message);
        return this;
    }

    public TR code(Integer code){
        this.setCode(code);
        return this;
    }

//    public TR data(Object data){
//        this.data.add(data);
//        return this;
//    }

    public TR data(Object data){
        this.setData(data);
        return this;
    }
}
